home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
msgq160s.arc
/
EDITBUF.C
< prev
next >
Wrap
Text File
|
1991-10-26
|
2KB
|
87 lines
/*
* EDITBUF.C - Message buffer manipulation
*
* Msged/Q message editor for QuickBBS Copyright 1990 by P.J. Muller
*
*/
#include <stdlib.h>
#include <string.h>
#include "msged.h"
/*
* Insert a line before another one and return it
* if (cur == NULL) add line at end
* The buffer is empty iff (buf->first == NULL)
* Return NULL on error
*/
LINE *insertline(BUFFER *buf, LINE *cur, char *txt)
{
LINE *t;
if (buf == NULL)
return NULL;
if ((t = (LINE *) calloc(1,sizeof(LINE))) == NULL) /* clear allocate */
return NULL; /* all fields of *t was cleared */
if (txt != NULL)
if ((t->text = strdup(txt)) == NULL) /* the text of the line */
return NULL;
t->next = cur; /* create links */
if (cur != NULL) {
t->prev = cur->prev;
if (cur->prev != NULL)
cur->prev->next = t;
cur->prev = t;
} else { /* add to end */
LINE *step; /* this little hack is here to */
if ((buf->last == NULL) || (buf->last->next != NULL)) {
if ((step = buf->first) != NULL) /* make up for the rest of */
while (step->next != NULL) /* things which don't always */
step = step->next; /* update msgbuf.last */
buf->last = step;
} /* if */
if ((step = buf->last) != NULL)
step->next = t;
t->prev = step;
buf->last = t; /* new last line */
} /* else */
if (buf->first == NULL) { /* buffer was empty */
buf->first = t;
buf->last = t;
} else {
if (buf->first == cur) /* current was first */
buf->first = t; /* so new is now first */
} /* else */
return(t);
} /* insertline */
/*
* Delete the line 'cur'
*/
void deleteline(BUFFER *buf, LINE *cur)
{
if ((buf == NULL) || (cur == NULL)) return;
if (buf->first == cur) /* cur is first line */
buf->first = cur->next;
if (buf->last == cur) /* cur is last line */
buf->last = cur->prev;
if (cur->prev != NULL)
cur->prev->next = cur->next;
if (cur->next != NULL)
cur->next->prev = cur->prev;
ptrfree(cur->text);
ptrfree(cur);
} /* deleteline */